<?php

namespace App\Http\Requests\Station\Network;

use Illuminate\Foundation\Http\FormRequest;

class RelationNetwork extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 定义表单规则
     *
     * Date: 2018/06/12
     * @author Tenny
     * @return array
     */
    public function rules()
    {
        return [
            'network_id' => 'required|integer',
            'credit' => ['required', 'regex:/^[0-9]+(.[0-9]{1,2})?$/'],
            'unit_price' => ['required', 'regex:/^[0-9]+(.[0-9]{1,2})?$/'],
        ];
    }

    /**
     * 定义错误响应消息
     *
     * Date: 2018/06/12
     * @author Tenny
     * @return array
     */
    public function messages()
    {
        return [
            'network_id.required' => '请选择网点',
            'network_id.integer' => '请选择正确的网点',
            'credit.required' => '信用不能为空',
            'credit.regex' => '信用的格式不正确',
            'unit_price.required' => '单价不能为空',
            'unit_price.regex' => '单价的格式不正确',
        ];
    }
}
